import java.util.*;
public class Day21 {
    public static void main(String[] args) {



        int[] a = {3,6,9,12};
        int aa  = calculate("3+2*2");
        System.out.println(aa);
    }
    //最长等差数列

    //基本计算机Ⅱ
    public static int calculate(String s) {
        Stack<Integer> stack = new Stack<>();
        char op = '+';
        int i=0;
        while(i<s.length()) {
            char ch = s.charAt(i);
            if(ch == ' ') {
                i++;
                continue;
            }
            if(ch<='9'&&ch>='0') {
                //是数字
                //1.提取完整数字
                int num = (int)(ch-'0');
                while(i+1<s.length() && s.charAt(i+1)>='0'&&s.charAt(i+1)<='9') {
                    num*=10;
                    num += (int)(s.charAt(i+1)-'0');
                    i++;
                }
                //2.进行计算
                if(op=='+') {
                    stack.push(num);
                }else if(op=='-'){
                    stack.push(-num);
                }else if(op=='*') {
                    stack.push(stack.pop()*num);
                }else {
                    stack.push(stack.pop()/num);
                }
            }else {
                //操作符
                op = ch;
            }
            i++;
        }
        int ret = 0;
        while(!stack.isEmpty()) ret += stack.pop();
        return ret;
    }

}
